package com.bykj.property.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bykj.property.controller.vo.request.NewsSendPageRequest;
import com.bykj.property.mapper.NewsSendMPmVillageMapper;
import com.bykj.property.model.NewsSend;
import com.bykj.property.mapper.NewsSendMapper;
import com.bykj.property.model.NewsSendMPmVillage;
import com.bykj.property.service.NewsSendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
    * 信息推送表 服务实现类
    * </p>
*
* @author liangyiming
* @since 2019-06-20
*/
@Service
public class NewsSendServiceImpl extends ServiceImpl<NewsSendMapper, NewsSend> implements NewsSendService {
@Autowired
private NewsSendMapper mapper;
    @Autowired
private NewsSendMPmVillageMapper npMapper;
@Override
public Page<NewsSend> queryPage(NewsSendPageRequest pageRequest) {

    return mapper.queryPage(pageRequest);
    }

    @Override
    public int saveNewPm(NewsSend model) {
        mapper.insert(model);
    String[] ids=model.getPmIds().split(",");
       for(String id:ids){
           NewsSendMPmVillage np=new NewsSendMPmVillage();
           np.setNewsSendId(model.getNewsSendId());
           np.setPmVillageId(Long.valueOf(id));
           npMapper.insert(np);
       }
        return 1;
    }

    @Override
    public int updatePm(NewsSend model) {
        mapper.updateById(model);
        QueryWrapper<NewsSendMPmVillage> queryWrapper=new QueryWrapper();
        queryWrapper.eq("news_send_id",model.getNewsSendId());
        npMapper.delete(queryWrapper);
        String[] ids=model.getPmIds().split(",");
        for(String id:ids){
            NewsSendMPmVillage np=new NewsSendMPmVillage();
            np.setNewsSendId(model.getNewsSendId());
            np.setPmVillageId(Long.valueOf(id));
            npMapper.insert(np);
        }
        return 1;

    }
}